from ctypes import cast, POINTER
import enum
from comtypes import CLSCTX_ALL
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume,ISimpleAudioVolume
devices = AudioUtilities.GetSpeakers()
interface = devices.Activate(
    IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
volume = cast(interface, POINTER(IAudioEndpointVolume))

def getCurrentMasterVolume():
    return int(round(volume.GetMasterVolumeLevelScalar() * 100))

def setMasterVolume(vol_percent:int):
    scalarVolume = vol_percent / 100
    volume.SetMasterVolumeLevelScalar(scalarVolume, None)
    return getCurrentMasterVolume()

class MuteStat(enum.Enum):
    MuteOn=1
    MuteOff=0

def mute(state:MuteStat):
    sessions = AudioUtilities.GetAllSessions()
    for session in sessions:
        volume = session._ctl.QueryInterface(ISimpleAudioVolume)
        volume.SetMute(state, None)

if __name__ == '__main__':    
    muted=volume.GetMute()
    print('muted:',muted)
    master_vol=getCurrentMasterVolume()
    print('master volume:',master_vol)
    master_vol=setMasterVolume(70)
    print('After change:',master_vol)